#include <iostream>
#include "use_add_dialog.h"

/**
 * We need that one to control user to be not
 * able tochoose for proper policies
 */
void UiAddPol::changePolicyDrop(int i){
    QString cur_temp_policy = this->comboPolicy->currentText();

    if(cur_temp_policy.compare("deny_all")==0 || cur_temp_policy.compare("allow_all")==0)
        this->treePersonList->setDisabled(true);
    else
        this->treePersonList->setDisabled(false);

}

/**Initialize the data into the 
 * dropdown menu and also load the people db
 *
 */

void UiAddPol::initializeDialogData(){
    
    const static char *VALID_POLICIES[] = {"deny_all","allow_all","allow_only","deny_only"};

    QStringList temPolList;

    for(int i=0;i<4;i++){
       temPolList << (QString)VALID_POLICIES[i];
     }

    //clear if we have previous
    this->comboPolicy->clear();
    this->comboPolicy->insertItems(0,temPolList);



    string temp_dir("learn"); //FIXME make it to get it from conf
    vector<string> f_list;

    ImageOpt temp_person_data;
    DbOperation *db = new DbOperation();
    //get images
    db->listImages(temp_dir,f_list);
    QStringList temp_plist;
    
    for(unsigned int i=0;i<f_list.size();i++){
        //parse the image
        db->parseImageName(f_list[i],&temp_person_data);
        std::cout<<"The person we got is :"<<temp_person_data.person_name<<endl;
        //now get the person name
        temp_plist << (QString)(temp_person_data.person_name);
    }
    //remove db instance
    delete db;
    db=0;


    //we need that one for tree
    QStringListModel *p_model=new      QStringListModel(temp_plist);
    
    treePersonList->setModel(p_model);
    //treePersonList->repaint();
    //
}


